package com.cloudcc.mobile.view.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.adapter.BusinesscardAdapter;
import com.cloudcc.mobile.adapter.BusinesscardAdapter.OnMyClickListener;
import com.cloudcc.mobile.dao.DownLoadCamCardDao;
import com.cloudcc.mobile.util.DialogUtils;
import com.cloudcc.mobile.util.DialogUtils.OnDoClickListener;
import com.cloudcc.mobile.view.base.BaseActivity;
import com.intsig.openapilib.OpenApi;
import com.intsig.openapilib.OpenApiParams;

/**
 * 名片扫描
 * 
 * @author Administrator
 * 
 */
public class BusinesscardScanningActivity extends BaseActivity implements OnMyClickListener {
	private static final float MAX_Z_DP = 10;
	private static final float MOMENTUM_SCALE = 10;
	private static final int MAX_ANGLE = 10;

	private LinearLayout lead, account;
	OpenApi openApi = OpenApi.instance("7y43139YE8TBXB98r17aRLyb");
	OpenApiParams apiParams = new OpenApiParams() {
		{
			this.setRecognizeLanguage("");
			this.setReturnCropImage(true);
			this.setSaveCard(true);
		}
	};

	public void init(Bundle savedInstanceState) {
		setupView();
	};

	@Override
	public int getLayoutId() {
		return R.layout.businesscardscanning;
	}

	private RecyclerView mRe;
	private BusinesscardAdapter adapter;
	@SuppressLint("NewApi")
	private void setupView() {
		TextView tvheader = (TextView) findViewById(R.id.header_title);
		tvheader.setText("名片扫描");
		findViewById(R.id.header_refresh).setVisibility(View.INVISIBLE);
		mRe=(RecyclerView) findViewById(R.id.rv1);
		adapter = new BusinesscardAdapter(this);
		adapter.setOnClickItemlistener(this);
		mRe.setAdapter(adapter);
		// 设置布局
		LinearLayoutManager layoutManager = new LinearLayoutManager(this,
				LinearLayoutManager.VERTICAL, false);
		mRe.setLayoutManager(layoutManager);
		
	}
	@Override
	public void onClickItem(int pos) {
		if (pos==0) {
			if (!openApi.isCamCardInstalled(mContext)) {
				tishi();
				return;
			}
			Intent i = new Intent(BusinesscardScanningActivity.this,
					CamCardActivity.class);
			i.putExtra("leixing", "lead");
			startActivity(i);
		}else if (pos==1) {
			if (!openApi.isCamCardInstalled(mContext)) {
				tishi();
				return;
			}
			Intent i = new Intent(BusinesscardScanningActivity.this,
					CamCardActivity.class);
			i.putExtra("leixing", "account");
			startActivity(i);
		}
	}

	protected void tishi() {
		DialogUtils dialog = new DialogUtils(mContext);
		String msg = "尚未安装名片全能名片王最新版\n 扫描名片需要安装名片全能王最新版，是否开始免费下载?";
		dialog.showCamDialog(mContext, msg);
		dialog.setOnDoClicktListener(new OnDoClickListener() {
			@Override
			public void confirm() {
				new DownLoadCamCardDao().downLoadCamcard(
						openApi.getDownloadLink(), mContext);
			}

			@Override
			public void cancel() {
			}
		});
	}

	public void clickBack(View v) {
		this.finish();
	}



}
